#ifndef __SOCKETFUNC_H_
#define __SOCKETFUNC_H_

#define MAXFILENAMESIZE (255+1)
#define SERVICENAMESIZE (127+1)

//the type of request
//请求类型
typedef enum ReqType{
	CREATNEWJOB,			//创建新任务
	TESTMODEL,				//测试模型
	REQPARAFILE,			//请求参数文件
	QUERYRATE,				//查询任务进度
	REQDELJOB,				//删除任务
	REQJOBRET,				//查询任务信息
	MODEL_NUM
}REQTYPE;

//define:the struct of message to query job-rate
typedef struct{
	REQTYPE  type;
	
	int num;
	int jobID[254];
}queryRateMsg;

//define:the struct of message to create new-job
typedef struct {
	REQTYPE  type;
	int jobID;
	
	char modeName[SERVICENAMESIZE];
	char dataFile[MAXFILENAMESIZE];
	char paraFile[MAXFILENAMESIZE];
	char rsltFile[MAXFILENAMESIZE];	
	//pad to size of "queryRateMsg"
	unsigned char charzero[sizeof(queryRateMsg) - 
			sizeof(REQTYPE) - 
			sizeof(int) - 
			SERVICENAMESIZE - 
			(MAXFILENAMESIZE *3)];
}creatNewJobMsg;

//define:the struct of message to test model
typedef struct {
	REQTYPE  type;
	
	int steplen;
	char modeName[SERVICENAMESIZE]; 
	char modeFile[MAXFILENAMESIZE];
	char dataFile[MAXFILENAMESIZE];
	char rsltFile[MAXFILENAMESIZE];
	//pad to size of "queryRateMsg"
	unsigned char charzero[sizeof(queryRateMsg) - 
			sizeof(REQTYPE) - 
			sizeof(int)     -
			SERVICENAMESIZE - 
			(MAXFILENAMESIZE * 3)];
}testModelMsg;

//define:the struct of message to request param-file of a model
typedef struct {
	REQTYPE  type;
	
	char modeName[SERVICENAMESIZE];
	char rsltFile[MAXFILENAMESIZE];
	//pad to size of "queryRateMsg"
	unsigned char charzero[sizeof(queryRateMsg) - 
			sizeof(REQTYPE) -
			SERVICENAMESIZE -
			MAXFILENAMESIZE];
}reqParamMsg;

//define:the struct of message to request delete job
typedef struct{
	REQTYPE type;
	
	int num;
	int jobIDs[254];
}reqDelJobMsg;

//define:the struct of message to query job result
typedef struct{
	REQTYPE type;
	int jobID;
	
	char rslt[MAXFILENAMESIZE];
	//pad to size of "queryRateMsg"
	unsigned char charzaro[sizeof(queryRateMsg) - 
			sizeof(REQTYPE) - 
			sizeof(int) - 
			MAXFILENAMESIZE];
}reqJobRet;

//////////////////////////////////////////////////////
#define SOCKET int
static inline SOCKET creatConn();
static        int    recvFile(SOCKET socket);
static        int    sendFile(SOCKET socket, const char* desFileName, char* srcFileName);
//////////////////////////////////////////////////////

//添加声明
//在.c文件添加实现 
//将所有功能综合到一起，
//在main.c文件中调用测试
void *serverStartup(void* args);

typedef int HandleRequest(int socket, void* msg);

int handleReqNewJobMsg(int socket, void *msg);
int handleReqParamFileMsg(int socket, void *msg);
int handleReqQueryRateMsg(int socket, void *msg);
int handleReqTestModelMsg(int socket, void *msg);
int handleReqDelJobMsg(int socket, void *msg);
int handleReqJobRet(int socket, void *msg);

#endif
